package models

import "time"

type Order struct {
	ID          uint        `gorm:"primaryKey" json:"id"`
	OrderNumber string      `gorm:"size:64;uniqueIndex;not null" json:"order_number"`
	Customer    string      `gorm:"size:100;not null" json:"customer"`
	Contact     string      `gorm:"size:100" json:"contact"`
	Status      string      `gorm:"size:50;default:'pending'" json:"status"`
	TotalAmount float64     `gorm:"not null" json:"total_amount"`
	CreatedAt   time.Time   `json:"created_at"`
	Items       []OrderItem `json:"items"`
}

type OrderItem struct {
	ID        uint    `gorm:"primaryKey" json:"id"`
	OrderID   uint    `gorm:"index;not null" json:"order_id"`
	ProductID uint    `gorm:"index;not null" json:"product_id"`
	Title     string  `gorm:"size:255;not null" json:"title"`
	Price     float64 `gorm:"not null" json:"price"`
}

func (Order) TableName() string {
	return "orders"
}

func (OrderItem) TableName() string {
	return "order_items"
}
